{% extends 'base/base.html' %}
{% load tags %}

{% block css %}
    <link href="/static/css/plugins/datapicker/datepicker3.css" rel="stylesheet">
    <link href="/static/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
    <link href="/static/css/plugins/bootstrap-markdown/bootstrap-markdown.min.css" rel="stylesheet">
{% endblock %}

{% block title %}ITAdmin | 批量处理(SaltStack)--添加Salt模块{% endblock %}


{% block body %}
<div class="ibox-content">
    <form class="form-horizontal">
        <div class="form-group"><label class="col-sm-2 control-label">名称<font color="red">*</font></label>
            <div class="col-sm-5"><input type="text" class="form-control" id="name" value="{{ cmd.name }}"></div>
        </div>

        <div class="hr-line-dashed"></div>

        <div class="form-group"><label class="col-sm-2 control-label">模块名<font color="red">*</font></label>
            <div class="col-sm-1"><input type="text" class="form-control" id="cmd" value="{{ cmd.cmd }}"></div>
        </div>

        <div class="hr-line-dashed"></div>

        <div class="form-group"><label class="col-sm-2 control-label">参数</label>
            <div class="col-sm-1"><input type="text" class="form-control" id="args" value="{{ cmd.args }}"></div>
        </div>

        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-2 control-label">备注</label>
            <div class="col-sm-5">
                <textarea name="content" id="desc" data-provide="markdown" rows="10" class="md-input" style="resize: none; display: block;">{{ cmd.description }}</textarea>
            </div>
        </div>

        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <div class="col-sm-4 col-sm-offset-5">
                <button class="btn btn-outline btn-warning dim" type="button" id="cancel_add"><i class="fa fa-warning"></i>取消</button>
                <button class="btn btn-primary dim" type="button" id="add"><i class="fa fa-check"></i>保存</button>
            </div>
        </div>
    </form>
</div>

{% endblock %}


{% block base_script %}
    <script src="/static/js/plugins/datapicker/bootstrap-datepicker.js"></script>
    <script src="/static/js/plugins/sweetalert/sweetalert.min.js"></script>
    <script src="/static/js/plugins/bootstrap-markdown/bootstrap-markdown.js"></script>
    <script src="/static/js/plugins/bootstrap-markdown/markdown.js"></script>
{% endblock %}

{% block script %}
<script>
    $(document).ready(function() {

        $('#date_added').datepicker({
            todayBtn: "linked",
            keyboardNavigation: false,
            forceParse: false,
            calendarWeeks: true,
            autoclose: true
        });

        $('#date_modified').datepicker({
            todayBtn: "linked",
            keyboardNavigation: false,
            forceParse: false,
            calendarWeeks: true,
            autoclose: true
        });

    });
</script>

<script type="text/javascript">

    $(function () {
        $("#add").click(function () {
            {% if cmd.id %}
                var cmd_id = {{ cmd.id }}
            {% else %}
                var cmd_id = '';
            {% endif %}
            var cmd = $('#cmd').val();
            var args = $('#args').val();
            var desc = $('#desc').val();
            var name = $('#name').val();
            if (cmd == '') {
                swal({cmd:"错误!", text:"模块名不可为空", type:"error"});
                return;
            }
            if (name == '') {
                swal({name:"错误!", text:"名称不可为空", type:"error"});
                return;
            }
            $.post("{% url 'addmodel' %}", {name: name, description: desc, cmd_id: cmd_id, args: args, cmd: cmd},function (data) {

                if (data.status == 1) {
                    swal({title:"成功!", text:"添加命令成功", type:"success"},function () {
                        location.href = "{% url 'saltcmd' %}";
                    });

                } else {
                    swal({title:"错误!", text:data.msg, type:"error"}, function () {
                        location.href = "{% url 'addmodel' %}";
                    });
                }
            }, 'json');
        })
        $('#cancel').click(function () {
            location.href = "{% url 'addmodel' %}";
        });
    });
</script>
{% endblock %}